<?php
// +----------------------------------------------------------------------
// | 萤火商城系统 [ 致力于通过产品和服务，帮助商家高效化开拓市场 ]
// +----------------------------------------------------------------------
// | Copyright (c) 2017~2023 https://www.yiovo.com All rights reserved.
// +----------------------------------------------------------------------
// | Licensed 这不是一个自由软件，不允许对程序代码以任何形式任何目的的再发行
// +----------------------------------------------------------------------
// | Author: 萤火科技 <admin@yiovo.com>
// +----------------------------------------------------------------------
declare (strict_types=1);

namespace app\store\model;

use app\common\model\RecommendImage as RecommendImageModel;

/**
 * 商品图片模型
 * Class GoodsImage
 * @package app\store\model
 */
class RecommendImage extends RecommendImageModel
{
    /**
     * 批量写入轮播图片记录
     * @param int $goodsId
     * @param array $imageIds
     * @return array|false
     */
    public static function increased(int $recommendId, array $imageIds)
    {
        $dataset = [];
        foreach ($imageIds as $imageId) {
            $dataset[] = [
                'recommend_id' => $recommendId,
                'image_id' => $imageId,
                'store_id' => self::$storeId
            ];
        }
        return (new static)->addAll($dataset);
    }

    /**
     * 更新关系记录
     * @param int $goodsId
     * @param array $imageIds 新的图片集
     * @return array|false
     */
    public static function updates(int $recommendId, array $imageIds)
    {
        // 删除所有的sku记录
        static::deleteAll(['recommend_id' => $recommendId]);
        // 批量写入商品图片记录
        return static::increased($recommendId, $imageIds);
    }


    //获取推荐商品详情的商品图片
    public function getDataList(int $recommendId){
        $list = $this->with(['file'])
            ->where('recommend_id', '=', $recommendId)
            ->order(['id' => 'asc'])
            ->select();

        $newlist = array();
        foreach($list as $k=>$v){
            $newlist[$k] = $v['file']; 

        }   
        return $newlist;
        
    }


}
